﻿'use strict';
app
    // Login Box controller 
    .controller('RegisterController', [
        '$rootScope', '$scope', '$state', '$localStorage', '$http', '$modal', function ($rootScope, $scope, $state, $localStorage, $http, $modal) {
            $scope.User = { Sponsor: '', UserName: '', Email: '', Password: '', Password2: '', SDTNHARIENG: '' },
            $scope.processing = false,
            $scope.popup = function (windowClass) {
                 $modal.open({
                     windowClass: windowClass,
                     templateUrl: "WarningModal",
                     controller: "RegisterModalInstanceCtrl",
                     size: "sm",
                     resolve: {
                         messeger: function () {
                             return $scope.messeger;
                         },
                         title: function () {
                             return $scope.title;
                         }
                     }
                 })
             },
            $scope.doSignup = function (User) {
                $scope.processing = true,
                $http.post($rootScope.APIUrl + 'Signup', { register: User }).then(function successCallback(resp) {
                    $scope.checkSponsor = 0, $scope.title = 'Login';
                    $scope.messeger = resp.data.Messeger;
                    if (resp.data.Status) {
                        $scope.popup('modal-message modal-success'), $state.go('login');
                    } else {
                        $scope.popup('modal-message modal-warning');
                    }
                    $scope.processing = false;
                }, function errorCallback(resp) {
                    $scope.processing = false;
                    if (resp.status == 0) {
                        $scope.checkSponsor = 0;
                        $scope.messeger = "Contact the Administrator by supporting",
                        $scope.title = 'Signup',
                        $scope.popup('modal-message modal-warning');
                    }
                })
                //console.log(signupData);
            }
        }
    ])
app.controller('RegisterModalInstanceCtrl', function ($scope, $modalInstance, messeger, title) {
    $scope.messeger = messeger;
    $scope.title = title;
    $scope.ok = function () {
        $modalInstance.close();
    };
    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    };
});